﻿using System;
using UnityEditor;

namespace ZyGame.Game
{
    public static class EntityExtension
    {
        public static bool HasComponent<T>(this Entity entity) where T : EntityComponent
        {
            return HasComponent(entity, typeof(T));
        }

        public static bool HasComponent(this Entity entity, Type type)
        {
            return EntityManager.instance.HasComponent(entity, type);
        }

        public static T AddComponent<T>(this Entity entity, params object[] dataList) where T : EntityComponent, new()
        {
            return (T)AddComponent(entity, typeof(T), dataList);
        }

        public static EntityComponent AddComponent(this Entity entity, Type type, params object[] dataList)
        {
            return EntityManager.instance.AddComponent(type, entity, dataList);
        }

        public static T GetComponent<T>(this Entity entity) where T : EntityComponent
        {
            return (T)entity.GetComponent(typeof(T));
        }

        public static EntityComponent GetComponent(this Entity entity, Type t)
        {
            return EntityManager.instance.GetComponent(t, entity);
        }

        public static EntityComponent[] GetComponents(this Entity entity)
        {
            return EntityManager.instance.GetComponents(entity);
        }

        public static bool DestroyComponent<T>(this Entity entity) where T : EntityComponent
        {
            return DestroyComponent(entity, typeof(T));
        }

        public static bool DestroyComponent(this Entity entity, Type t)
        {
            return EntityManager.instance.ReleaseComponent(entity, t);
        }

        public static void ClearComponent(this Entity entity)
        {
            EntityManager.instance.ClearComponent(entity);
        }
    }
}
